/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package canvas;

import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
import midlet.MidletPlay;
import util.RecordHighScore;

/**
 * @author LTTDNQ
 */
public class MIDPCanvasHighScore extends GameCanvas implements CommandListener {

    private MidletPlay _midlet;
    private Graphics _g;
    private Command _cmExit = new Command("Exit", Command.EXIT, 1);
    private Image _imgBg;
    private int _chieudai = getWidth();
    private int _chieucao = getHeight();
    private RecordHighScore rmsgs;
    /**
     * constructor
     */
    public MIDPCanvasHighScore(MidletPlay midlet) {
        super(false);
        this._midlet = midlet;
        layHighScore();
        _g = this.getGraphics();
        try {
            // Set up this canvas to listen to command events
            setCommandListener(this);
            // Add the Exit command
            addCommand(_cmExit);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    private void layHighScore(){
        rmsgs = RecordHighScore.getInstance();
        rmsgs.printScores();
//            rmsgs.addScore(110, "5");
//            rmsgs.printScores();
//            RecordHighScore.playerNameFilter = "Acheson";
//            rmsgs.printScores("Acheson");
    }
    /**
     * paint
     */
    public void paintHighScore() {
        try {
            _imgBg = Image.createImage("/Images/imgBackground.png");
            _g.drawImage(_imgBg, 0, 0, Graphics.LEFT | Graphics.TOP);
            Font font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_LARGE);
            _g.setColor(255, 0, 0);
            _g.setFont(font);
            _g.drawString("HIGH SCORE", _chieudai * 4 / 10, _chieucao * 3 / 10 + 5, Graphics.LEFT | Graphics.TOP);
            _g.drawString(String.valueOf(rmsgs.getArrInt()[0]), _chieudai * 5 / 10, _chieucao * 4 / 10 + 5, Graphics.LEFT | Graphics.TOP);
            _g.drawString(String.valueOf(rmsgs.getArrInt()[1]), _chieudai * 5 / 10, _chieucao * 5 / 10 + 5, Graphics.LEFT | Graphics.TOP);
            _g.drawString(String.valueOf(rmsgs.getArrInt()[2]), _chieudai * 5 / 10, _chieucao * 6 / 10 + 5, Graphics.LEFT | Graphics.TOP);
            _g.drawString(String.valueOf(rmsgs.getArrInt()[3]), _chieudai * 5 / 10, _chieucao * 7 / 10 + 5, Graphics.LEFT | Graphics.TOP);
            _g.drawString(String.valueOf(rmsgs.getArrInt()[4]), _chieudai * 5 / 10, _chieucao * 8 / 10 + 5, Graphics.LEFT | Graphics.TOP);
        } catch (IOException ex) {
            ex.printStackTrace();
        }

    }


    /**
     * Called when a key is pressed.
     */
    protected void keyPressed(int keyCode) {
    }

    /**
     * Called when a key is released.
     */
    protected void keyReleased(int keyCode) {
    }

    /**
     * Called when a key is repeated (held down).
     */
    protected void keyRepeated(int keyCode) {
    }

    /**
     * Called when the pointer is dragged.
     */
    protected void pointerDragged(int x, int y) {
    }

    /**
     * Called when the pointer is pressed.
     */
    protected void pointerPressed(int x, int y) {
    }

    /**
     * Called when the pointer is released.
     */
    protected void pointerReleased(int x, int y) {
    }

    /**
     * Called when action should be handled
     */
    public void commandAction(Command command, Displayable displayable) {
        if (command == _cmExit) {
            _midlet.vaoManHinhMenu();
        }
    }
}
